package com.my.emp_manage.common.utils;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine;
import org.springframework.beans.factory.annotation.Value;

import java.util.Collections;

/**
 * @author zhupanlin
 * @version 1.0
 * @description: TODO
 * @date 2023/12/22 20:57
 */
public class MybatisCodeGenerator {

    private static String url = "jdbc:mysql://localhost:3306/springdb";
    
    private static String username = "root";
    
    private static String password = "sb";
    
    public static void main(String[] args) {
        FastAutoGenerator.create(url, username, password)
                .globalConfig(builder -> {
                    builder.author("baomidou") // 设置作者
                            .enableSwagger() // 开启 swagger 模式
                            .fileOverride() // 覆盖已生成文件
                            .outputDir("D://"); // 指定输出目录
                })
                
                .packageConfig(builder -> {
                    builder.parent("com/my/emp_manage") // 设置父包名
                            .moduleName("emp_manage") // 设置父包模块名
                            .pathInfo(Collections.singletonMap(OutputFile.xml, "D://")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude("employee")
                            .addInclude("department");// 设置需要生成的表名
                })
                .templateEngine(new VelocityTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }
    
}
